package com.test.reggie.http;

import com.tencent.mmkv.MMKV;
import com.test.reggie.bean.AddAddressBean;
import com.test.reggie.bean.AddShoppingCartBean;
import com.test.reggie.bean.AddressBookDetailsBean;
import com.test.reggie.bean.AddressBookListBean;
import com.test.reggie.bean.CategoryListBean;
import com.test.reggie.bean.DishListBean;
import com.test.reggie.bean.ShoppingCartListBean;
import com.test.reggie.bean.StringBean;
import com.test.reggie.bean.UserBean;

import java.util.Map;

import io.reactivex.Observable;
import retrofit2.http.Body;
import retrofit2.http.DELETE;
import retrofit2.http.GET;
import retrofit2.http.POST;
import retrofit2.http.PUT;
import retrofit2.http.Path;
import retrofit2.http.Query;

/**
 * 接口的管理类
 */
public class API {

    public static MMKV kv = MMKV.defaultMMKV();

    public interface Api {
        //登录
        @POST("user/login")
        Observable<UserBean> login(@Body Map<String, Object> map);

        //退出登录
        @POST("user/logout")
        Observable<StringBean> logout();

        //注册
        @POST("user/regist")
        Observable<StringBean> regist(@Body Map<String, Object> map);

        //根据id查询用户信息
        @GET("user/{id}")
        Observable<UserBean> userDetails(@Path("id") String id);

        //新增地址
        @POST("addressBook")
        Observable<AddAddressBean> addAddress(@Body Map<String, Object> map);

        //查询指定用户的全部地址
        @GET("addressBook/list")
        Observable<AddressBookListBean> addressBookList(@Query("userId") String userId);

        //设置默认地址
        @PUT("addressBook/default")
        Observable<AddAddressBean> setDefault(@Body Map<String, Object> map);

        //查询默认地址
        @GET("addressBook/default")
        Observable<AddAddressBean> getDefault(@Query("userId") String userId);

        //根据id查询地址
        @GET("addressBook/{id}")
        Observable<AddressBookDetailsBean> addressBookDetails(@Path("id") String id);

        //修改地址
        @PUT("addressBook")
        Observable<StringBean> updateAddressBook(@Body Map<String, Object> map);

        //删除地址
        @DELETE("addressBook")
        Observable<StringBean> deleteAddressBook(@Query("ids") String ids);

        //根据条件查询分类数据
        @GET("category/list")
        Observable<CategoryListBean> categoryList();

        //根据条件查询对应的菜品数据
        @GET("dish/list")
        Observable<DishListBean> dishList(@Query("categoryId") String categoryId);

        //根据条件查询套餐数据
        @GET("setmeal/list")
        Observable<DishListBean> setmealList(@Query("categoryId") String categoryId);

        //添加购物车
        @POST("shoppingCart/add")
        Observable<AddShoppingCartBean> addShoppingCart(@Body Map<String, Object> map);

        //编辑购物车
        @POST("shoppingCart/update")
        Observable<AddShoppingCartBean> updateShoppingCart(@Body Map<String, Object> map);

        //查看购物车
        @GET("shoppingCart/list")
        Observable<ShoppingCartListBean> shoppingCartList(@Query("userId") String userId);

        //清空购物车
        @DELETE("shoppingCart/clean")
        Observable<StringBean> cleanShoppingCart(@Query("userId") String userId);

        //用户下单
        @POST("orders/submit")
        Observable<StringBean> submitOrders(@Body Map<String, Object> map);
    }
}
